class MovieClipManager {
	public constructor() {
	}
	public mcDic: any = {};
    /**
     *
     * @param mcName 动画名字
     * @param thisObj 动画的父对象
     * @param playCom  播放动画完成动作
     * @param po 动画的坐标
     * @param _times 动画播放次数
     * @param _timeDispear 动画停留多少毫秒消失 1000 ,如果是负数，不消失
     * @param _index 动画在父对象中的层级 -1
	 * @param repeat 是否复制 false
	 * @param blendmode 图像的混合模式 “”
	 * @param play 加载完成后直接播放  true直接播放 “”
     */
	public newMc(mcName: string, thisObj: egret.DisplayObjectContainer, playCom: Function, po: egret.Point = null, _times: number, _timeDispear: number = 1000, _index: number = -1, repeat: boolean = false, blendmode: string = "", play: boolean = true, loadCom: Function = null,_scaleX:number=1) {
		var mc: egret.MovieClip;
		if (po == null)
			po = new egret.Point(0, 0);
		if (this.mcDic[mcName] == null || repeat == true) {
			GameMain.me.resource.getAnim(mcName, (_mcdata: egret.MovieClipData) => {
				mc = new egret.MovieClip(_mcdata);
				mc.scaleX = _scaleX;
				if (_times > 0) {
					if (!mc.hasEventListener(egret.Event.COMPLETE)) {
						mc.addEventListener(egret.Event.COMPLETE, (e: egret.Event) => {
							//console.log(e.type);//
							if (_timeDispear >= 0) {
								egret.setTimeout((paramsArr: any) => {
									var _mc = paramsArr[0] as egret.MovieClip;
									if (_mc.parent != null) {
										_mc.parent.removeChild(_mc);
									}
								}, this, _timeDispear, [mc]);

							}
							if (playCom != null)
								playCom(mc);
						}, this);
					}
				}
				if (blendmode != "")
					mc.blendMode = egret.BlendMode.ADD;

				if (thisObj == null) {//因为碰的时候，把牌移除了，但是又要怼牌进行播放闪电特效，冲突了
					return;
				}
				if (_index == -1)
					thisObj.addChild(mc);
				else
					thisObj.addChildAt(mc, _index);
				if (play)
					mc.gotoAndPlay(1, _times);
				mc.x = po.x;
				mc.y = po.y;
				if (loadCom != null)
					loadCom(mc);
				this.mcDic[mcName] = mc;
				//mc.touchEnabled = false;
			}, this);

		} else {
			mc = this.mcDic[mcName];
				mc.scaleX = _scaleX;
			
			if (_times > 0) {
				if (!mc.hasEventListener(egret.Event.COMPLETE)) {
					mc.addEventListener(egret.Event.COMPLETE, (e: egret.Event) => {
						//console.log(e.type);//
						if (_timeDispear >= 0) {
							egret.setTimeout((paramsArr: any) => {
								var _mc = paramsArr[0] as egret.MovieClip;

								if (_mc.parent != null) {
									_mc.parent.removeChild(_mc);
								}
							}, this, _timeDispear, [mc]);
						}
						if (playCom != null)
							playCom(mc);
					}, this);
				}
			}
			if (thisObj == null) {//因为碰的时候，把牌移除了，但是又要怼牌进行播放闪电特效，冲突了
				return;
			}
			if (_index == -1)
				thisObj.addChild(mc);
			else
				thisObj.addChildAt(mc, _index);
			mc.x = po.x;
			mc.y = po.y;
			mc.stop();
			if (play)
				mc.gotoAndPlay(1, _times);
			if (loadCom != null)
				loadCom(mc);
			//mc.touchEnabled = false;
		}

	}
	public deleteMc(mcName: string) {
		if (this.mcDic[mcName] != null) {
			var mc = this.mcDic[mcName];
			if (mc.parent != null) {
				mc.parent.removeChild(mc);
			}
			//this.mcDic[mcName] = null;
		}
	}

	public getMc(mcName: string) {
		if (this.mcDic[mcName] != null) {
			var mc = this.mcDic[mcName];
			return mc;
		}
		return null;
	}


}